	<script type="text/javascript">
		$(document).ready(function(){
			$("#datepicker1").datepicker({
		      dateFormat: "dd/mm/yy",
		      changeMonth: true,
		      changeYear: true
		    });
		});
		$(document).ready(function(){
			$("#dokter").select2({
			    placeholder: "Pilih Dokter"
			});
			$("#unit").select2({
			    placeholder: "Pilih Unit"
			});
		});
	</script>
		<div class="row">
		    <div class="col-xs-12">
		        <div class="box box-primary">
		            <div class="box-header">
		                <h3 class="box-title">Tambah Data Klaim Obat & ABHP</h3>
		            </div><!-- /.box-header -->
		            <?php echo form_open('apotik/update', array('role' => 'form', 'id' => 'form'));?>
		            <div class="box-body col-xs-12 col-lg-6">				        
	                    <!-- text input -->
	                    <div class="form-group">
	                        <label>Kode Klaim</label>
	                        <div class="input-group input-group-sm">
	                       		<input class="form-control" name="kd_klaim" id="kd_klaim" value="<?= $list['kd_klaim']?>" type="text" placeholder="Masukkan kode klaim" style="z-index:0;" readonly="">
	                       		<input class="form-control" name="id_klaim_obat" id="id_klaim_obat" value="<?= $list['id_klaim_obat']?>" type="hidden" placeholder="Masukkan kode klaim" style="z-index:0;" readonly="">
	                       		<span class="input-group-btn">
	                       			<a class="btn btn-info btn-flat" href="#" onClick="return kd_peserta()"><i class="fa fa-check"></i></a>
	                       		</span>
	                        </div>
	                        </div>
			                 <div class="form-group">
		                       <label>Unit</label><br/>
		                       <select class="form-control input-sm unit" name="unit" id="unit" style="width:100%;">
		                       <?php 
		                       			foreach ($unit as $value) { 
		                       				if ($value['KDUNIT']!=$list['KDUNIT']) {
				                                continue;
				                            }
				                            echo '<option value="'.$value['KDUNIT'].'">'.$value['unit'].'</option>';

		                       			}
		                       		?>
		                       		<?php 
		                       			foreach ($unit as $value) { 
		                       				if ($value['KDUNIT']==$list['KDUNIT']) {
				                                continue;
				                            }
				                            echo '<option value="'.$value['KDUNIT'].'">'.$value['unit'].'</option>';

		                       			}
		                       		?>
		                       </select>
		                    </div>
		                    <div class="form-group">
		                        <label>Dokter</label><br/>
		                       <select class="form-control input-sm dokter" name="dokter" id="dokter" style="width:100%;">
		                       		<?php 
		                       			foreach ($dokter as $value) { 
		                       				if ($value['KDDOK']!=$list['KDDOK']) {
				                                continue;
				                            }
				                            echo '<option value="'.$value['KDDOK'].'">'.$value['dokter'].'</option>';

		                       			}
		                       		?>
		                       		<?php 
		                       			foreach ($dokter as $value) { 
		                       				if ($value['KDDOK']==$list['KDDOK']) {
				                                continue;
				                            }
				                            echo '<option value="'.$value['KDDOK'].'">'.$value['dokter'].'</option>';

		                       			}
		                       		?>
		                       </select>
		                    </div>
	                </div>
	                <div class="box-body col-xs-12 col-lg-6">
	                    <div class="form-group">
		                    <label>Tanggal Transaksi</label>
		                    <input class="form-control input-sm" name="tgl_transaksi" id="datepicker1" value="<?= id_date($list['tgl_transaksi'],'short_b'); ?>" type="text" placeholder="Tanggal Transaksi..."> 
		                 </div>
		                 <div class="form-group">
		                    <label>No. DMK</label>
		                    <input class="form-control input-sm" name="dmk" id="dmk" type="text" value="<?= $list['dmk'] ?>" placeholder="No. DMK">
		                 </div>
		            </div>
	                <div class="clearfix"></div>
		            <div class="box-body col-xs-12 col-lg-6">
		            	<div class="form-group">
	                        <label>No. Peserta</label>
	                       	<input class="form-control input-sm" name="nopeserta" id="nopeserta" type="text" disabled>
	                       	<input class="form-control input-sm" name="klaim_obat" id="klaim_obat" type="hidden" disabled>
	                    </div>
	                    <div class="form-group">
	                        <label>Nama Peserta</label>
	                       	<input class="form-control input-sm" name="nama" id="nama" type="text" readonly="">
	                    </div>
		            </div>
		            <div class="box-body col-xs-12 col-lg-6">
		            	<div class="form-group">
	                        <label>TTL Peserta</label>
	                       	<input class="form-control input-sm" name="ttl" id="ttl" type="text" disabled>
	                    </div>
	                     <div class="form-group">
	                        <label>Alamat Peserta</label>
	                       	<input class="form-control input-sm" name="alamat" id="alamat" type="text" disabled>
	                    </div>	
		            </div>	
		            <div class="box-body col-xs-12">
                         <button type="submit" class="btn btn-sm btn-primary btn-flat"><i class="fa fa-floppy-o"></i> Simpan</button>
                    </div>
					<?php echo form_close();?>
		            <div class="box-body" id="tab" style="display:none;">

						  <!-- Tab panes -->
						  <div class="tab-content" style="width:100%">
						    <div role="tabpanel" class="tab-pane fade in active" id="layanan">
						    	<label>Obat & ABHP</label><br/><!--
						    	<label class="pull-right">Total </label><input type="text" name="ltotal" id="ltotal" disabled="">
								-->
								<span class="notif notif-danger" id="notif" style="display:none;">
				            		<i class="fa fa-check"></i>
				            		Maaf, obat/ABHP yang anda input sudah ada
				            		<button type="button" class="close">&times;</button>
				            	</span>
					            <table class="table table-borderless table-hover table-condensed table-striped">
					              <thead>
					              	<tr>
					              		<th width="2%">#</th>
					              		<th width="5%">Kode</th>
					              		<th width="20%">Obat & ABHP</th>
					              		<th width="10%">Tarif Perda</th>
					              		<th width="5%">Jumlah</th>
					              		<th width="10%">Tarif Diminta</th>
					              		<th width="15%">Sub Total</th>
					              		<th width="10%">
					              		
					              		</th>
					              	</tr>
					              </thead>
					              <form id="formApotik">
					              <thead>
					              	<tr>

					              		<th></th>
					              		<th>
					              			<input type="text" name="kd_obat" id="kd_obat" class="form-control input-sm">
					              		</th>
					              		<th width="20%" id="pilih_obat">
					              		</th>
					              		<th width="10%">
					              			<input type="hidden" name="kd_klaim2" id="kd_klaim2">
					              			<input class="form-control input-sm" name="tarif_perda" id="tarif_perda" type="text" disabled=""> 
					              		</th>
					              		<th width="5%">
					              			<input class="form-control input-sm" name="jumlah" id="jumlah" type="text" placeholder=""> 
					              		</th>
					              		<th width="10%">
					              			<input class="form-control input-sm" name="tarif_diminta" id="tarif_diminta" type="text" placeholder="Tarif Diminta"> 
					              		</th>
					              		<th width="15%">
					              			<input class="form-control input-sm subtotal" name="subtotal" id="subtotal" type="text" disabled=""> 
					              		</th>
					              		<th width="10%">
					              			<button id="save" type="button" class="btn btn-sm btn-success btn-flat"><i class="fa fa-floppy-o"></i> Simpan</button>
					              		</th>
					              	</tr>
					              </thead>
					              </form>		
					              <tbody id="tbl-apotik">            
					                                  
					              </tbody>
					              
					            </table>
						    </div>
						  </div>
		            </div>
		            <div class="clearfix"></div>		                   
                    
		        </div><!-- /.box -->                            
		    </div>
		</div>

		<script type="text/javascript">
		$(document).ready(function () {
			$("#master_diagnosa").select2({
			    placeholder: "Pilih Diagnosa"
			});

		});
		</script>
		<script>
		$("#form").validate({
			rules: {
				
				kd_klaim: {
					required: true
				},
			}
		});
		</script>
		<script type="text/javascript">
		  window.onload=function kd_peserta(){
		    var send_data = {
		        kd_peserta: $("#kd_klaim").val(),
		        <?php echo $this->security->get_csrf_token_name(); ?>: "<?php echo $this->security->get_csrf_hash(); ?>",
		      };

		    $.ajax({
		      type: "POST",
		      url: "<?php echo base_url() ?>apotik/get_klaim",
		      data: send_data,
		      cache: false,
		      dataType: 'json',
		      success: function(msg){
		        $("#nama").val(msg.nama);
		        $("#nopeserta").val(msg.nopeserta);
		        $("#alamat").val(msg.alamat);
		        $("#ttl").val(msg.ttl);
		        $("#klaim_obat").val(msg.id_klaim_obat);
		        if (msg.stts=="ada") {
		        	document.getElementById("tab").style.display = "inline-block";
		        	document.getElementById("kd_klaim2").value = $("#kd_klaim").val();
					//document.getElementById("kd_obat").value='';
					document.getElementById("formApotik").reset();
		        	document.getElementById("kd_obat").focus();
		        }else{
		        	document.getElementById("tab").style.display = "none";
		        };
		        
		      }
		    });

		    //get klaim layanan
		    $.ajax({
			      url: "<?php echo base_url() ?>apotik/get_apotik_klaim/"+$('#id_klaim_obat').val()+"",
			      cache: false,
			      dataType: 'html',
			      success: function(msg){
			        $("#tbl-apotik").html(msg);
			      }
			    });

			  
			// get layanan
		    $.ajax({
		        url: '<?php echo base_url() ?>apotik/get_apotik/'+$("#kd_klaim").val()+'',
			    //data: send_data,
			    cache: false,
			    dataType: 'html',
		        success: function(data){
		            $('#pilih_obat').html(data);
		            $("#master_obat").select2({
			            placeholder: "Pilih Obat ABHP"
			        });
		        }
		    });

		     $.ajax({
		        url: '<?php echo base_url() ?>apotik/get_apotik_kode/'+$("#kd_klaim").val()+'',
			    //data: send_data,
			    cache: false,
			    dataType: 'html',
		        success: function(data){
		            $('#pilih_kode').html(data);
		            $("#master_kdobat").select2({
			            placeholder: "Masukan Kode Obat"
			        });
		        }
		    });
		  }
		  
		  function pilih_obat(kd_obat)
			{
			    var data_send = {
			        obat: kd_obat,
			        <?php echo $this->security->get_csrf_token_name(); ?>: "<?php echo $this->security->get_csrf_hash(); ?>",
			      };
			    $.ajax({
			      type: "POST",
			      url: "<?php echo base_url() ?>apotik/get_obat_by",
			      data: data_send,
			      cache: false,
			      dataType: 'json',
			      success: function(msg){
			        $("#tarif_perda").val(msg.harga);
			        $("#subtotal").val(msg.harga);
			        $("#tarif_diminta").val(msg.harga);
			        $("#kd_obat").val(msg.kd_obat);
			        $("#jumlah").val(msg.jumlah);
			      }
			    }); 
			} 

			function get_apotik_klaim()
			{
			    $.ajax({
			      url: "<?php echo base_url() ?>apotik/get_apotik_klaim/"+$('#id_klaim_obat').val()+"",
			      cache: false,
			      dataType: 'html',
			      success: function(msg){
			        $("#tbl-apotik").html(msg);
			      }
			    }); 
			}

			

		</script>
		<script type="text/javascript">
		        $(document).ready(function () {
		            $('#jumlah').keyup(function(){
		                var jml = parseInt(document.getElementById("jumlah").value);
		                var tarif = parseInt(document.getElementById("tarif_diminta").value);
		                var tot=jml*tarif;
		                document.getElementById('subtotal').value = tot;

		                
		            });
		            $('#tarif_diminta').keyup(function(){
		                var jml = parseInt(document.getElementById("jumlah").value);
		                var tarif = parseInt(document.getElementById("tarif_diminta").value);
		                var tot=jml*tarif;
		                document.getElementById('subtotal').value = tot;
		            });
		        });

		</script>
		<script type="text/javascript">
		//save layanan
	    $(document).ajaxComplete(function(){
	    	
	        $("#save").click(function() {
	            //jika valid
	            if($("#master_obat").val()!="" && $("#jumlah").val()>0 && $("#tarif_diminta").val()>0){
	            var form_data = {
	                kd_obat: $("#master_obat").val(),
	                klaim_obat: $("#id_klaim_obat").val(),
	                tarif_perda: $("#tarif_perda").val(),
	                jumlah: $("#jumlah").val(),
	                tarif_diminta: $("#tarif_diminta").val(),
	                // ini harus ada, untuk scurity CI   
	                <?php echo $this->security->get_csrf_token_name();?>: '<?php echo $this->security->get_csrf_hash();?>'
	              };

	            $.ajax({
	                type: "POST",
	                data: form_data,
	                url: "<?php echo site_url('apotik/simpan_obat');?>",
	                error: function(e){
	                	document.getElementById("notif").style.display="block";
					        document.getElementById("formApotik").reset();
		        			document.getElementById("kd_obat").focus();
	                },
	                success: function(e) {
	                    $.ajax({
					      url: "<?php echo base_url() ?>apotik/get_apotik_klaim/"+$('#id_klaim_obat').val()+"",
					      cache: false,
					      dataType: 'html',
					      success: function(msg){
					        $("#tbl-apotik").html(msg);
					        document.getElementById("notif").style.display="none";
					        document.getElementById("formApotik").reset();
		        			document.getElementById("kd_obat").focus();
					      }
					    }); 
	                },
	            });
	            stopPropagation();
	          }
	        });
	    });
	       
	     //delete layanan
	     function hapusObat(obj){  
		    if (confirm('Apakah data akan dihapus ?')) {
		      var data_delete = {
			        obat: obj,
			        klaim: $('#id_klaim_obat').val(),
			        <?php echo $this->security->get_csrf_token_name(); ?>: "<?php echo $this->security->get_csrf_hash(); ?>",
			      };
			    $.ajax({
			      type: "POST",
			      url: "<?php echo base_url() ?>apotik/delete_obat",
			      data: data_delete,
			      cache: false,
			      dataType: 'html',
			      success: function(msg){
			        $("#tbl-apotik").html(msg);
			      }
			    });
		    }
		  }

		  //edit layanan
	     function editObat(obj){ 
		      var data_edit = {
			        obat: obj,
			        <?php echo $this->security->get_csrf_token_name(); ?>: "<?php echo $this->security->get_csrf_hash(); ?>",
			      };
			    $.ajax({
			      type: "POST",
			      url: "<?php echo base_url() ?>apotik/edit_obat",
			      data: data_edit,
			      cache: false,
			      dataType: 'html',
			      success: function(msg){
			        $("#div_"+obj).html(msg);
			        $('#ejumlah').keyup(function(){
		                var jml = parseInt(document.getElementById("ejumlah").value);
		                var tarif = parseInt(document.getElementById("etarif_diminta").value);
		                var tot=jml*tarif;
		                document.getElementById('esubtotal').value = tot;

		               
		            });
		            $('#etarif_diminta').keyup(function(){
		                var jml = parseInt(document.getElementById("ejumlah").value);
		                var tarif = parseInt(document.getElementById("etarif_diminta").value);
		                var tot=jml*tarif;
		                document.getElementById('esubtotal').value = tot;
		            });
			      }
			    });
		  }
		  //update layanan
		  $(document).ajaxComplete(function(){
	    	
	        $("#update").click(function() {
	            //jika valid
	            if($("#ejumlah").val()>0 && $("#etarif_diminta").val()>0){
	            var update_data = {
	                id: $("#id_obat_klaim").val(),
	                tarif_perda: $("#etarif_perda").val(),
	                jumlah: $("#ejumlah").val(),
	                tarif_diminta: $("#etarif_diminta").val(),
	                // ini harus ada, untuk scurity CI   
	                <?php echo $this->security->get_csrf_token_name();?>: '<?php echo $this->security->get_csrf_hash();?>'
	              };

	            $.ajax({
	                type: "POST",
	                data: update_data,
	                url: "<?php echo site_url('apotik/update_obat');?>",
	                success: function(e) {
	                    $.ajax({
					      url: "<?php echo base_url() ?>apotik/get_apotik_klaim/"+$('#id_klaim_obat').val()+"",
					      cache: false,
					      dataType: 'html',
					      success: function(msg){
					        $("#tbl-apotik").html(msg);
					      }
					    });
	                },
	            });
	            stopPropagation();
	          }
	        });
	    });
		//get by kode
		$(document).ready(function(){
	    	
	        $("#kd_obat").keyup(function() {
	           
	            var get_data = {
	                obat: $("#kd_obat").val(),
	                // ini harus ada, untuk scurity CI   
	                <?php echo $this->security->get_csrf_token_name();?>: '<?php echo $this->security->get_csrf_hash();?>'
	              };

	            $.ajax({
			      type: "POST",
			      url: "<?php echo base_url() ?>apotik/get_obat_by",
			      data: get_data,
			      cache: false,
			      dataType: 'json',
			      success: function(msg){
			        $("#tarif_perda").val(msg.harga);
			        $("#subtotal").val(msg.harga);
			        $("#tarif_diminta").val(msg.harga);
			        $("#kd_obat").val(msg.kd_obat);
			        $("#master_obat").select2("val",msg.kd_obat);
			        $("#jumlah").val(msg.jumlah);
			        //document.getElementById(msg.kd_obat).selected = "true";
			      }
			    });
	            stopPropagation();
	        });
			//save ketika menekan enter
			 $("#tarif_diminta").keypress(function(e) {
	            var keyCode = e.keyCode || e.which;
	            if(keyCode==13){
	            if($("#master_obat").val()!="" && $("#jumlah").val()>0 && $("#tarif_diminta").val()>0){
	            var form_data = {
	                kd_obat: $("#master_obat").val(),
	                klaim_obat: $("#id_klaim_obat").val(),
	                tarif_perda: $("#tarif_perda").val(),
	                jumlah: $("#jumlah").val(),
	                tarif_diminta: $("#tarif_diminta").val(),
	                // ini harus ada, untuk scurity CI   
	                <?php echo $this->security->get_csrf_token_name();?>: '<?php echo $this->security->get_csrf_hash();?>'
	              };

	            $.ajax({
	                type: "POST",
	                data: form_data,
	                url: "<?php echo site_url('apotik/simpan_obat');?>",
	                error: function(e){
	                	document.getElementById("notif").style.display="block";
					        document.getElementById("formApotik").reset();
		        			document.getElementById("kd_obat").focus();
	                },
	                success: function(e) {
	                    $.ajax({
					      url: "<?php echo base_url() ?>apotik/get_apotik_klaim/"+$('#id_klaim_obat').val()+"",
					      cache: false,
					      dataType: 'html',
					      success: function(msg){
					        $("#tbl-apotik").html(msg);
					        document.getElementById("notif").style.display="none";
					        document.getElementById("formApotik").reset();
		        			document.getElementById("kd_obat").focus();
					      }
					    }); 
	                },
	            });
	            stopPropagation();
	          }
	          }
	        });

			$("#jumlah").keypress(function(e) {
	            var keyCode = e.keyCode || e.which;
	            if(keyCode==13){
	            if($("#master_obat").val()!="" && $("#jumlah").val()>0 && $("#tarif_diminta").val()>0){
	            var form_data = {
	                kd_obat: $("#master_obat").val(),
	                klaim_obat: $("#id_klaim_obat").val(),
	                tarif_perda: $("#tarif_perda").val(),
	                jumlah: $("#jumlah").val(),
	                tarif_diminta: $("#tarif_diminta").val(),
	                // ini harus ada, untuk scurity CI   
	                <?php echo $this->security->get_csrf_token_name();?>: '<?php echo $this->security->get_csrf_hash();?>'
	              };

	            $.ajax({
	                type: "POST",
	                data: form_data,
	                url: "<?php echo site_url('apotik/simpan_obat');?>",
	                error: function(e){
	                	document.getElementById("notif").style.display="block";
					        document.getElementById("formApotik").reset();
		        			document.getElementById("kd_obat").focus();
	                },
	                success: function(e) {
	                    $.ajax({
					      url: "<?php echo base_url() ?>apotik/get_apotik_klaim/"+$('#id_klaim_obat').val()+"",
					      cache: false,
					      dataType: 'html',
					      success: function(msg){
					        $("#tbl-apotik").html(msg);
					        document.getElementById("notif").style.display="none";
					        document.getElementById("formApotik").reset();
		        			document.getElementById("kd_obat").focus();
					      }
					    }); 
	                },
	            });
	            stopPropagation();
	          }
	          }
	        });

			$("#kd_obat").keypress(function(e) {
	            var keyCode = e.keyCode || e.which;
	            if(keyCode==13){
	            if($("#master_obat").val()!="" && $("#jumlah").val()>0 && $("#tarif_diminta").val()>0){
	            var form_data = {
	                kd_obat: $("#master_obat").val(),
	                klaim_obat: $("#id_klaim_obat").val(),
	                tarif_perda: $("#tarif_perda").val(),
	                jumlah: $("#jumlah").val(),
	                tarif_diminta: $("#tarif_diminta").val(),
	                // ini harus ada, untuk scurity CI   
	                <?php echo $this->security->get_csrf_token_name();?>: '<?php echo $this->security->get_csrf_hash();?>'
	              };

	            $.ajax({
	                type: "POST",
	                data: form_data,
	                url: "<?php echo site_url('apotik/simpan_obat');?>",
	                error: function(e){
	                	document.getElementById("notif").style.display="block";
	                	document.getElementById("kd_obat").value="";
					    document.getElementById("formApotik").reset();
		        		document.getElementById("kd_obat").focus();
	                },
	                success: function(e) {
	                    $.ajax({
					      url: "<?php echo base_url() ?>apotik/get_apotik_klaim/"+$('#id_klaim_obat').val()+"",
					      cache: false,
					      dataType: 'html',
					      success: function(msg){
					        $("#tbl-apotik").html(msg);
					        document.getElementById("kd_obat").focus();
					        //document.getElementById("formApotik").reset();
					        document.getElementById("notif").style.display="none";
					        //document.getElementById("kd_obat").value="";
					      }
					    }); 
	                },
	            });
	            stopPropagation();
	          }
	          }
	        });
	    });
		</script>
		
		